package com.lambda.lambda;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author zhaoyunlong
 * @date 2020/11/9
 * @DESCRIPTION
 */
public class Test {

    static String put(){
        System.out.println("this is put");
        return "put";
    }

    static void get(Integer value){
        System.out.println("this is put");
    }

    static String toUpperCase(String str){
        return str.toUpperCase();
    }

    public static void main(String[] args) {

        /**
         * 静态方法引用
         */
        Supplier<String> stringSupplier = ()->{return Test.put();};
        Supplier<String> stringSupplier1 = ()->Test.put();
        Supplier<String> stringSupplier2 = ()->"3345";
        Supplier<String> stringSupplier3 = Test::put;

        Consumer<Integer> consumer = Test::get;
        Consumer<Integer> consumer1 =(size)->{Test.get(size);};
        consumer.accept(123);


        Function<String, String> function = s -> s.toUpperCase();
        Function<String, String> function2 = s -> Test.toUpperCase(s);
        Function<String, String> function1 =  Test::toUpperCase;
        System.out.println(function.apply("abc"));
        System.out.println(function2.apply("abc"));
        System.out.println(function1.apply("abc"));

        /**
         * 对象方法引用
         */

        Consumer<String> tooConsumer3  = new Too()::toUpperCase;

        /**
         * 类方法引用
         */
        Consumer<Too> tooConsumer  = (Too too)->{ new Too().fond();};
        Consumer<Too> tooConsumer1  = Too::fond;
        tooConsumer.accept(new Too());
        tooConsumer1.accept(new Too());

        /**
         * 构造方法引用
         */

        Supplier<Too1> supplier1 = ()->{
            // 此时的内部类需要添加static修饰
            Too1 too1 =  new Test.Too1()
          return too1;};

        Supplier<Too1> supplier2 = ()->{
            Test test = new Test();
            Too1 too1 = test.new Too1();
            return too1;};

        Supplier<Too> supplier3 = Too::new;

        Function<String, Too> function3 = (str)->{
            return new Too(str);
        };
        Function<String, Too> function4 = Too::new;
        System.out.println(function3.apply("abc"));
        System.out.println(function4.apply("abc"));
    }


     class Too1{

        public Too1(){
            System.out.println("thiis is no arg instance");
        }

        public Too1(String arg){
            System.out.println("thiis is  arg instance" + arg);
        }
    }

}

 class Too{

    public Too(){
        System.out.println("thiis is no arg instance");
    }

    public Too(String arg){
        System.out.println("thiis is  arg instance" + arg);
    }

     public void fond(){
         System.out.println("this is fond");
     }

     public void toUpperCase(String str){
         System.out.println(str);
     }
}
